home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / sndhrdw / senjyo.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  2KB  |  107 lines

  1. #include "driver.h"
  2. #include "machine/z80fmly.h"
  3. #include <math.h>
  4.  
  5.  
  6. /* z80 pio */
  7. static void pio_interrupt(int state)
  8. {
  9.     cpu_cause_interrupt (1, Z80_VECTOR(0,state) );
  10. }
  11.  
  12. static z80pio_interface pio_intf =
  13. {
  14.     1,
  15.     {pio_interrupt},
  16.     {0},
  17.     {0}
  18. };
  19.  
  20. /* z80 ctc */
  21. static void ctc_interrupt (int state)
  22. {
  23.     cpu_cause_interrupt (1, Z80_VECTOR(1,state) );
  24. }
  25.  
  26. static z80ctc_interface ctc_intf =
  27. {
  28.     1,                   /* 1 chip */
  29.     { 0 },               /* clock (filled in from the CPU 0 clock */
  30.     { NOTIMER_2 },       /* timer disables */
  31.     { ctc_interrupt },   /* interrupt handler */
  32.     { z80ctc_0_trg1_w }, /* ZC/TO0 callback */
  33.     { 0 },               /* ZC/TO1 callback */
  34.     { 0 }                /* ZC/TO2 callback */
  35. };
  36.  
  37.  
  38. /* single tone generator */
  39. #define SINGLE_LENGTH 10000
  40. #define SINGLE_DIVIDER 8
  41.  
  42. static signed char *_single;
  43. static int single_rate = 1000;
  44. static int single_volume = 0;
  45. static int channel;
  46.  
  47.  
  48. WRITE_HANDLER( senjyo_volume_w )
  49. {
  50.     single_volume = data & 0x0f;
  51.     mixer_set_volume(channel,single_volume * 100 / 15);
  52. }
  53.  
  54. int senjyo_sh_start(const struct MachineSound *msound)
  55. {
  56.     int i;
  57.  
  58.  
  59.     channel = mixer_allocate_channel(15);
  60.     mixer_set_name(channel,"Tone");
  61.  
  62.     /* z80 ctc init */
  63.     ctc_intf.baseclock[0] = Machine->drv->cpu[1].cpu_clock;
  64.     z80ctc_init (&ctc_intf);
  65.  
  66.     /* z80 pio init */
  67.     z80pio_init (&pio_intf);
  68.  
  69.     if ((_single = (signed char *)malloc(SINGLE_LENGTH)) == 0)
  70.     {
  71.         free(_single);
  72.         return 1;
  73.     }
  74.     for (i = 0;i < SINGLE_LENGTH;i++)        /* freq = ctc2 zco / 8 */
  75.         _single[i] = ((i/SINGLE_DIVIDER)&0x01)*127;
  76.  
  77.     /* CTC2 single tone generator */
  78.     mixer_set_volume(channel,0);
  79.     mixer_play_sample(channel,_single,SINGLE_LENGTH,single_rate,1);
  80.  
  81.     return 0;
  82. }
  83.  
  84.  
  85.  
  86. void senjyo_sh_stop(void)
  87. {
  88.     free(_single);
  89. }
  90.  
  91.  
  92.  
  93. void senjyo_sh_update(void)
  94. {
  95.     double period;
  96.  
  97.     if (Machine->sample_rate == 0) return;
  98.  
  99.  
  100.     /* ctc2 timer single tone generator frequency */
  101.     period = z80ctc_getperiod (0, 2);
  102.     if( period != 0 ) single_rate = (int)(1.0 / period );
  103.     else single_rate = 0;
  104.  
  105.     mixer_set_sample_frequency(channel,single_rate);
  106. }
  107.